package org.leviatan.dataharbour.core.persistance.impl;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.leviatan.common.xml.XMLIO;
import org.w3c.dom.Document;

public abstract class DefaultHibernateController {
	
	private static final SessionFactory hibernateSession;
	
	private static final Document cfgDoc;
	
	static {
		cfgDoc = XMLIO.getInstance().readXMLFile(
				"D:/dev/shared_dev/proj/DataHarbour/hibernate.cfg.xml");
		try {
            // Create the SessionFactory from hibernate.cfg.xml
            hibernateSession = new Configuration()
            
            	.addResource("HarbourRequestImpl")
        		.addResource("PersistableDataEntityImpl")
        		
            	.configure(cfgDoc)
            	.buildSessionFactory();
            
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
	}
	
	public static SessionFactory getSessionFactory() {
        return DefaultHibernateController.hibernateSession;
    }

}
